﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UIDATALayer;

namespace UserData
{
    public partial class Control_SN : TextBox,Interface_UserControl
    {
        string strSNName = "Sensor码";
        [Category("SN名称")]
        public string SN名称
        {
            set { strSNName = value; }
            get { return strSNName; }
        }

        public Control_SN()
        {
            InitializeComponent();
        }
        private UIDATALayer.UIDataAction<SNData> acSNData = null;

        private void Control_SN_Load(object sender, EventArgs e)
        {
        }
        public void Init()
        {
            SNHelper.OnTest_ShowSN += ShowSN;
            SNHelper.OnTest_ReflushSN += ReflushSN;

        }
        public void ReflushSN(string strName)
        {
            if (InvokeRequired)
            {
                this.Invoke(new Action(() => { ReflushSN(strName); }));
            }
            else
            {
                if (strName == strSNName)
                {
                    this.Text = "";
                    this.Focus();
                }
            }
        }
        public void ShowSN(string strName, string strSN)
        {
            if (acSNData == null)
            {
                UIDATALayerHelper.RegistAction<SNData>(nameof(SNData), ShowSN).Start();
                acSNData = UIDATALayer.UIDATALayerHelper.GetRegistAction<SNData>(nameof(SNData));
            }
            if (strName == this.SN名称)
            {
                SNData data = new SNData();
                data.strTypeName = strName;
                data.strSnValue = strSN;
                acSNData.SetData(data);

            }
        }
        public void ShowSN(SNData data)
        {
            if (InvokeRequired)
            {
                this.Invoke(new Action(() => { ShowSN(data); }));
            }
            else
            {
                if (data.strTypeName == strSNName)
                    this.Text = data.strSnValue;
            }
        }

        public string Function_GetSN()
        {
            return this.Text;
        }
    }
}
